import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class HouseItem extends StatefulWidget {
  const HouseItem({super.key, required this.itemMap});
  final Map<String, dynamic> itemMap;

  @override
  State<HouseItem> createState() => _HouseItemState();
}

class _HouseItemState extends State<HouseItem> {
  Widget getStatusList() {
    var colors = getStatusColor();
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5),
      decoration: BoxDecoration(
        color: colors[0],
        borderRadius: BorderRadius.circular(5),
      ),
      child: Text(
        getStatusText(),
        style: TextStyle(
          color: colors[1],
        ),
      ),
    );
  }

//审核状态文字状态
  String getStatusText() {
    switch (widget.itemMap['status']) {
      case 1:
        return '正在审核';
      case 2:
        return '审核成功';
      case 3:
        return '审核失败';
      default:
        return '未知';
    }
  }

//审核状态颜色
  List<Color> getStatusColor() {
    switch (widget.itemMap['status']) {
      case 1:
        return const [
          Color.fromARGB(50, 0, 0, 255),
          Color.fromARGB(255, 0, 0, 255)
        ];
      case 2:
        return const [
          Color.fromARGB(50, 0, 255, 0),
          Color.fromARGB(255, 0, 255, 0)
        ];
      case 3:
        return const [
          Color.fromARGB(50, 255, 0, 0),
          Color.fromARGB(255, 255, 0, 0)
        ];
      default:
        return const [
          Color.fromARGB(50, 255, 0, 0),
          Color.fromARGB(255, 0, 0, 255)
        ];
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: const EdgeInsets.all(10),
        decoration: const BoxDecoration(
          color: Colors.white,
        ),
        child: GestureDetector(
          onTap: () {
            Navigator.pushNamed(context, "/house_detail",
                arguments: {"id": widget.itemMap["id"]});
          },
          child: Column(
            children: [
              Row(
                children: [
                  Expanded(child: Text(widget.itemMap["point"])),
                  const Spacer(),
                  getStatusList()
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  const Text(
                    '房间号',
                    style: TextStyle(color: Colors.grey),
                  ),
                  const Spacer(),
                  Expanded(
                    child: Text(
                      widget.itemMap["room"],
                      textAlign: TextAlign.right,
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 15),
              Row(
                children: [
                  const Text(
                    '业主',
                    style: TextStyle(color: Colors.grey),
                  ),
                  const Spacer(),
                  Expanded(
                    child: Text(
                      widget.itemMap["name"],
                      textAlign: TextAlign.right,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ));
  }
}
